﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Arkanoide
{
    class Tijolo
    {

        Texture2D texture;
        Vector2 position;
        Rectangle size;
        GameWindow janela;
        SoundEffect soundEffect;
        bool Visible;
       // public static int contador = 0;
        public static List<Tijolo> parede = new List<Tijolo>();
        Bola esfera;
    

        public Tijolo(GameWindow janela, Texture2D texture, Vector2 position, SoundEffect soundEffect)
        {
            this.texture = texture;
            this.position = position;
            this.janela = janela;
            this.size = texture.Bounds;
            this.soundEffect = soundEffect;
            this.Visible = true;
            //contador++;
            parede.Add(this);

        }

        public void LoadContent()
        {
           
        }

        public void Update()
        {
            //atualiza a posicao do retangulo do tijolo de acordo com  a sua posicao 

            for (int u = 0; u < parede.Count; u++)
            {
                parede[u].size.X = (int)parede[u].position.X;
                parede[u].size.Y = (int)parede[u].position.Y;
            }
        }

        public void Colision(Rectangle bola)
        {
            for (int u = 0; u < parede.Count; u++)
            {
                if (bola.Intersects(parede[u].size) && parede[u].Visible)
                {
//                  esfera.ColisionBrick( (int) ((bola.X - position.X)/size.Width/2 )  );
                    
                    //Remove o tijolo atingido
                    parede[u].Visible = false;
                    parede[u].soundEffect.Play();
                    parede.RemoveAt(u);
                    //this.position = new Vector2(10 + position.X/50, 10 + position.Y/50);
                    //contador--;
                    
 
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            for (int u = 0; u < parede.Count; u++)
            {
                if (parede[u].Visible)
                {
                    spriteBatch.Draw(parede[u].texture, parede[u].position, Color.White);

                }
            }
        }

    }
}
